package io.gitee.zhangbinhub.acp.boot.init

import io.gitee.zhangbinhub.acp.boot.component.SystemControl
import io.gitee.zhangbinhub.acp.boot.listener.AcpApplicationStopListener
import io.gitee.zhangbinhub.acp.boot.log.LogAdapter
import io.gitee.zhangbinhub.acp.boot.tools.ServerTools
import io.gitee.zhangbinhub.acp.core.common.CommonTools

/**
 * 系统初始化
 */
class SystemInitialization(
    private val logAdapter: LogAdapter,
    private val serverTools: ServerTools,
    private val systemControl: SystemControl
) : AcpInitialization {

    override val name: String
        get() = "System Initialization"

    override fun doInit() {
        logAdapter.info("<<<<<<<<<<<<<<<<<<<< System is starting ... >>>>>>>>>>>>>>>>>>>>")
        /* 启动 listener 及定时任务 */
        systemControl.initialization()
        Runtime.getRuntime().addShutdownHook(Thread { AcpApplicationStopListener.stopAllService() })
        logAdapter.info("<<<<<<<<<<<<<<<<<<<< System startup completed on port ${serverTools.getServerPort()}! Default charset is ${CommonTools.getDefaultCharsetName()} >>>>>>>>>>>>>>>>>>>>")
    }
}